import datetime
import os
import sys

import getPltResult
from Base import GetYamlFile
from Base.WriteExcel import Write_excel
from GetData.GetBugResults import get_search_result, get_result, get_unresolved_bugs_result, get_bug_by_template_result
from GetData import GetTestCase
path = os.path.dirname(sys.path[0])
sys.path.append(path)

rows={
    "消防智能监控系统":4,
    "渠道大平台":5,
    "电管家":6,
    "IOT平台系统":7,
    "消防实战平台":8,
    "授权系统":9,
    "智慧用电":10,
    "智慧社区":11,
    "消防后勤系统":12,
    "数字用电":13
}
cols={
    "BUG总数":3,
    "未解决BUG数":4,
    "新增BUG数":5,
    "今日已解决":6,
    "今日已关闭":7
}
r_rows={
        "厉江涛":15,
        "王佳辉":16,
        "黄其涵":17,
        "吴浩东":18,
        "周清江":19,
        "何牡禄":20,
        "徐康":21,
        "朱圣刚":22,
        "张万平":23,
        "陈治建":24,
        "李倍佳":25,
        "宋泽森":26,
        "詹佳敏":27,
        "李剑龙":28,
}
r_cols={
    "消防智能监控系统":3,
    "渠道大平台":5,
    "电管家":4,
    "IOT平台系统":6,
    "消防实战平台":7,
    "授权系统":8,
    "智慧用电":9,
    "智慧社区":10,
    "消防后勤系统":11,
    "数字用电":12
}
headers = {
    "Content-Type": "application/x-www-form-urlencoded",
}
#写入结果到excel表格
def WriteResult():
    getbugpath=GetYamlFile.getBugPath("BugPath")
    # print(REPORT_XLSX_DIR)
    wt=Write_excel(getbugpath,"Result")
    today = datetime.datetime.now().strftime('%Y-%m-%d')
    # print(today)
    ksj="  "
    # wt.write(2,2,str(today))
    wt.write(2,2,today)
    for row in range(4,12):
        for col in range(3,8):
            wt.write(row,col,0)
    list1=GetTestCase.get_serch_test_case()
    list2=GetTestCase.get_test_case()
    list3 =GetTestCase.get_unresolved_bugs_case()
    result = get_search_result(list1, headers)
    result2 = get_result(list2)
    result3 = get_unresolved_bugs_result(list3)
    print(result2)
    for item in result:
        wt.write(rows[item["name"]],cols[item["type"]],int(item["bug"]))
    for item in result2[0]:
        wt.write(rows[item["name"]],cols[item["type"]],int(item["bug"]))
    wx=Write_excel(getbugpath,"R_Result")
    for row  in range(15,29):
        for col in range(3,13):
            wx.write(row,col,None)
    for items in result2[1]:
        for item in items[1]:
            if int(items[1][item])==0:
                pass
            else:
                # print(int(items[1][item]))
                wx.write(r_rows[item],r_cols[items[0]],int(items[1][item]))
    wy =Write_excel(getbugpath,"U_Result")
    for row in range(2, 100):
        for col in range(1, 6):
            wy.write(row, col, None)
    r=2
    for item in result3 :
        wy.write(r,1,item["name"])
        wy.write(r,2,item["bugId"])
        wy.write(r,3,item["bugDescribe"])
        wy.write(r,4,item["bugByP"])
        wy.write(r,5,item["delaytime"])
        r+=1

    template_result=get_bug_by_template_result()
    #获取为解决bug
    getPltResult.get_result(result2[1])
    #懒得重新修改代码，直接返回所需结果
    return template_result,result3
if __name__ == '__main__':
    statrtime=datetime.datetime.now()
    WriteResult()
    endtime=datetime.datetime.now()
    runTime=endtime-statrtime
    print(runTime)
